package com.scqzy.shengchunqiang.sword2offer.day04;

/**
 * @Description: 剑指 Offer 53 - II. 0～n-1中缺失的数字
 * @Author 盛春强
 * @Date 2021/8/11 20:12
 */
public class MissingNumber {
    public int missingNumber(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] != mid) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return nums[left] == left ? left + 1 : left;
    }
}
